package cn.demographic.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.demographic.entity.Registry;
import cn.demographic.service.RegistryService;

/**
 * 审核状态接口
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/Register")
public class RegisterController {
	@Autowired
	private RegistryService registryService;
	
	/**
	 * 查询注册信息审核列表
	 * @param session
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findRegistryAudit")
	public Map<String, Object> findRegistryAudit(HttpSession session,String state,
			String unit,String name,String phone,String stateTime,String endTime,
			String pageNoStr,String pageSizeStr){
		//获取参数
		long pageNo = 1;	//如果没有传数据,默认为第一页
		if( pageNoStr != null && pageNoStr.trim().length()>0 ){
			pageNo = Long.parseLong(pageNoStr);
		}
		int pageSize = 5;	//如果没有传数据,默认为10条数据
		if( pageSizeStr != null && pageSizeStr.trim().length()>0 ){
			pageSize = Integer.parseInt(pageSizeStr);
		}
		long beginNo = (pageNo-1)*pageSize;
		/*获取登录人权限*/
		Registry registry = (Registry) session.getAttribute("registry");
		Integer permissionsId = registry.getPermissionsId();
		//获取地址，市级
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("liveCity", registry.getLive().getCity() );
		map.put("permissionsId", permissionsId);
		map.put("unit", unit);
		map.put("name", name);
		map.put("phone", phone);
		map.put("state", state);
		map.put("stateTime", stateTime);
		map.put("endTime", endTime);
		map.put("beginNo", beginNo);
		map.put("pageSize", pageSize);
		List<Registry> registerList = registryService.findRegistryAudit(map);
		Long count = registryService.findCountRegistryAudit(map);
		Map<String, Object> mapList = new HashMap<String, Object>();
		mapList.put("registerList", registerList);
		mapList.put("count", count);
		return mapList;
	}
	
	/**
	 * 根据id修改审核状态
	 * @param id
	 * @param state
	 * @param session
	 */
	@RequestMapping("/updateRegistry")
	public Map<String,Object> updateRegistry(Integer[] ids, Integer state, HttpSession session) {
		Integer[] id = new Integer[ids.length-1];
		for (int i = 0; i < id.length; i++) {
			id[i] = ids[i];
		}
		registryService.UpdateRegistryAudit(id, state);
		Map<String,Object> map = new HashMap<String,Object>();
		return map;
	}
	
	
}
